package C;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        while (n-- > 0) {
            StringBuffer result = new StringBuffer();
            String str = sc.nextLine();
            for (int i = 0; i < str.length(); i++) {
                char c = str.charAt(i);
                if (c == 'R') {
                    result = result.reverse();
                } else if (c == 'Z') {
                    if (i == 0) {
                        continue;
                    }
                    if (str.charAt(i - 1) == 'R') {
                        result = result.reverse();
                    } else {
                        result=  result.deleteCharAt(result.length() - 1);
                    }
                } else {
                    result=  result.append(c);
                }
            }
            System.out.println(result);
        }
    }
}
